package my.hw;

import java.util.*;

import android.app.Activity;
import android.graphics.Point;

public class Board {
	private static final int D = 8;
	private Grid[][] grids= new Grid[D][D];
	
	public Grid[] getGrids() {
		Grid[] result= new Grid[D*D];
		for (int x=0; x<D; x++) {
			for (int y=0; y<D; y++) {
				result[y*D+x]= grids[x][y];
			}
		}
		return result;
//		List<Grid> lst= new ArrayList<Grid>(D*D);
//		for (Grid[] row : grids) {
//			for (Grid grid : row) {
//				lst.add(grid);
//			}
//		}
//		
//		return lst.toArray(new Grid[lst.size()]);
	}
	
	public Grid findGrid(Point position) {
		if (position.x < 0) return null;
		if (position.x >= D) return null;
		if (position.y < 0) return null;
		if (position.y >= D) return null;
		return grids[position.x][position.y];
	}
	
	public Board(Activity activity) {
		grids[0][0]= new Grid(new Point(0,0), activity.findViewById(R.id.btn1));
		grids[1][0]= new Grid(new Point(1,0), activity.findViewById(R.id.btn2));
		grids[2][0]= new Grid(new Point(2,0), activity.findViewById(R.id.btn3));
		grids[3][0]= new Grid(new Point(3,0), activity.findViewById(R.id.btn4));
		grids[4][0]= new Grid(new Point(4,0), activity.findViewById(R.id.btn5));
		grids[5][0]= new Grid(new Point(5,0), activity.findViewById(R.id.btn6));
		grids[6][0]= new Grid(new Point(6,0), activity.findViewById(R.id.btn7));
		grids[7][0]= new Grid(new Point(7,0), activity.findViewById(R.id.btn8));
		grids[0][1]= new Grid(new Point(0,1), activity.findViewById(R.id.btn9));
		grids[1][1]= new Grid(new Point(1,1), activity.findViewById(R.id.btn10));
		grids[2][1]= new Grid(new Point(2,1), activity.findViewById(R.id.btn11));
		grids[3][1]= new Grid(new Point(3,1), activity.findViewById(R.id.btn12));
		grids[4][1]= new Grid(new Point(4,1), activity.findViewById(R.id.btn13));
		grids[5][1]= new Grid(new Point(5,1), activity.findViewById(R.id.btn14));
		grids[6][1]= new Grid(new Point(6,1), activity.findViewById(R.id.btn15));
		grids[7][1]= new Grid(new Point(7,1), activity.findViewById(R.id.btn16));
		grids[0][2]= new Grid(new Point(0,2), activity.findViewById(R.id.btn17));
		grids[1][2]= new Grid(new Point(1,2), activity.findViewById(R.id.btn18));
		grids[2][2]= new Grid(new Point(2,2), activity.findViewById(R.id.btn19));
		grids[3][2]= new Grid(new Point(3,2), activity.findViewById(R.id.btn20));
		grids[4][2]= new Grid(new Point(4,2), activity.findViewById(R.id.btn21));
		grids[5][2]= new Grid(new Point(5,2), activity.findViewById(R.id.btn22));
		grids[6][2]= new Grid(new Point(6,2), activity.findViewById(R.id.btn23));
		grids[7][2]= new Grid(new Point(7,2), activity.findViewById(R.id.btn24));
		grids[0][3]= new Grid(new Point(0,3), activity.findViewById(R.id.btn25));
		grids[1][3]= new Grid(new Point(1,3), activity.findViewById(R.id.btn26));
		grids[2][3]= new Grid(new Point(2,3), activity.findViewById(R.id.btn27));
		grids[3][3]= new Grid(new Point(3,3), activity.findViewById(R.id.btn28));
		grids[4][3]= new Grid(new Point(4,3), activity.findViewById(R.id.btn29));
		grids[5][3]= new Grid(new Point(5,3), activity.findViewById(R.id.btn30));
		grids[6][3]= new Grid(new Point(6,3), activity.findViewById(R.id.btn31));
		grids[7][3]= new Grid(new Point(7,3), activity.findViewById(R.id.btn32));
		grids[0][4]= new Grid(new Point(0,4), activity.findViewById(R.id.btn33));
		grids[1][4]= new Grid(new Point(1,4), activity.findViewById(R.id.btn34));
		grids[2][4]= new Grid(new Point(2,4), activity.findViewById(R.id.btn35));
		grids[3][4]= new Grid(new Point(3,4), activity.findViewById(R.id.btn36));
		grids[4][4]= new Grid(new Point(4,4), activity.findViewById(R.id.btn37));
		grids[5][4]= new Grid(new Point(5,4), activity.findViewById(R.id.btn38));
		grids[6][4]= new Grid(new Point(6,4), activity.findViewById(R.id.btn39));
		grids[7][4]= new Grid(new Point(7,4), activity.findViewById(R.id.btn40));
		grids[0][5]= new Grid(new Point(0,5), activity.findViewById(R.id.btn41));
		grids[1][5]= new Grid(new Point(1,5), activity.findViewById(R.id.btn42));
		grids[2][5]= new Grid(new Point(2,5), activity.findViewById(R.id.btn43));
		grids[3][5]= new Grid(new Point(3,5), activity.findViewById(R.id.btn44));
		grids[4][5]= new Grid(new Point(4,5), activity.findViewById(R.id.btn45));
		grids[5][5]= new Grid(new Point(5,5), activity.findViewById(R.id.btn46));
		grids[6][5]= new Grid(new Point(6,5), activity.findViewById(R.id.btn47));
		grids[7][5]= new Grid(new Point(7,5), activity.findViewById(R.id.btn48));
		grids[0][6]= new Grid(new Point(0,6), activity.findViewById(R.id.btn49));
		grids[1][6]= new Grid(new Point(1,6), activity.findViewById(R.id.btn50));
		grids[2][6]= new Grid(new Point(2,6), activity.findViewById(R.id.btn51));
		grids[3][6]= new Grid(new Point(3,6), activity.findViewById(R.id.btn52));
		grids[4][6]= new Grid(new Point(4,6), activity.findViewById(R.id.btn53));
		grids[5][6]= new Grid(new Point(5,6), activity.findViewById(R.id.btn54));
		grids[6][6]= new Grid(new Point(6,6), activity.findViewById(R.id.btn55));
		grids[7][6]= new Grid(new Point(7,6), activity.findViewById(R.id.btn56));
		grids[0][7]= new Grid(new Point(0,7), activity.findViewById(R.id.btn57));
		grids[1][7]= new Grid(new Point(1,7), activity.findViewById(R.id.btn58));
		grids[2][7]= new Grid(new Point(2,7), activity.findViewById(R.id.btn59));
		grids[3][7]= new Grid(new Point(3,7), activity.findViewById(R.id.btn60));
		grids[4][7]= new Grid(new Point(4,7), activity.findViewById(R.id.btn61));
		grids[5][7]= new Grid(new Point(5,7), activity.findViewById(R.id.btn62));
		grids[6][7]= new Grid(new Point(6,7), activity.findViewById(R.id.btn63));
		grids[7][7]= new Grid(new Point(7,7), activity.findViewById(R.id.btn64));

	}
}
